<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>鼠标在盒子内的坐标</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			.box {
				width: 400px;
				height: 400px;
				background-color: pink;
				margin: 20px auto;
			}
		</style>
	</head>
	<body>
		<div class="box"></div>
		
		<script type="text/javascript">
			window.addEventListener('load',function() {
				var div = document.querySelector('div')
				div.addEventListener('mousemove',function(e) {
					//获取盒子的偏移量
					var ox =  div.offsetLeft;
					var oy = div.offsetTop;
					
					//获取鼠标在页面中的位置
					var x = e.pageX - ox;
					var y = e.pageY - oy;
					
					div.innerHTML = '鼠标在盒子里面的位置是:' + x + ',' + y;
					
					
				})
			})
		</script>
	</body>
</html>
